//
//  WLCollectionViewCell.m
//  ECommunicationGuard
//
//  Created by Visitor on 2017/7/12.
//  Copyright © 2017年 金亨日. All rights reserved.
//

#import "WLCollectionViewCell.h"
@interface WLCollectionViewCell ()

@property(nonatomic, strong)UIView *singleView;

@property(strong,nonatomic)UIImageView *iconView;

@property(nonatomic, strong)UILabel *shopLabel;
@end

@implementation WLCollectionViewCell
+ (instancetype)collectionViewCellWithCollectionView:(UICollectionView *)collectionView forIndexPath:(NSIndexPath *)indexPath
{
    static NSString * identifier = @"reuseWaterCollectionCell";
    WLCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
    if (cell==nil) {
        cell = [[WLCollectionViewCell alloc]initWithFrame:CGRectZero];
    }
    return cell;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self == [super initWithFrame:frame]) {
        
        UIView * singleView = [[UIView alloc] init];
//        singleView.layer.borderColor = RGB_S(241).CGColor;
//        singleView.layer.borderWidth =1.0;
        [self.contentView addSubview:singleView];
        self.singleView = singleView;
        
        UIImageView *imageView=[[UIImageView alloc]init];
        imageView.userInteractionEnabled = NO;
        imageView.backgroundColor = [UIColor clearColor];
        [singleView addSubview:imageView];
        self.iconView = imageView;
        
        UILabel *shopLabel = [[UILabel alloc] init];
        shopLabel.textColor = [UIColor colorWithRed:29/225.0 green:29/225.0 blue:38/225.0 alpha:1.0];
        shopLabel.userInteractionEnabled =NO;
        shopLabel.font = [UIFont boldSystemFontOfSize:12];
        shopLabel.textAlignment = NSTextAlignmentCenter;
        shopLabel.backgroundColor = [UIColor whiteColor];
        [singleView addSubview:shopLabel];
        self.shopLabel = shopLabel;
        
        //        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cellImageViewTapped:)];
        
        //        [singleView addGestureRecognizer:tap];
    }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.singleView.frame = CGRectMake(0, 0, SizeForItem , 79);
    self.iconView.frame = CGRectMake((self.frame.size.width - 44) *0.5, 7, 44, 44);
    self.shopLabel.frame = CGRectMake(0, CGRectGetMaxY(self.iconView.frame) + 5, SizeForItem, 21);
  
}

- (void)setDataDict:(NSDictionary *)dataDict
{
    _dataDict = dataDict;
    
    if (dataDict) {
        NSString *title = dataDict[@"title"];
        NSString *imageStr = dataDict[@"image"];
        
        self.iconView.image = [UIImage imageNamed:imageStr];
        self.shopLabel.text = title;
    }else{
        self.iconView.image= [UIImage imageNamed:@"add"];
        self.shopLabel.text = @"添加";
    }
   
    

}

//-(void)resetPhotosViewStatus
//{
//    self.singleView.hidden = YES;
//    self.singleView.frame = CGRectZero;
//}

//- (void)setDataShopperModel:(WLDataTotalShoppingModel *)dataShopperModel
//{
//    _dataShopperModel = dataShopperModel;
//    //cell的重用问题待解决
//    //    [self resetPhotosViewStatus];
//    
//    [self.iconView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%s%@",kImageURLAPIFormat,dataShopperModel.storefront_link_st]] placeholderImage:PLACEHOLDER_IMAGE];
//    self.shopLabel.text = dataShopperModel.name_bm;
//}
-(void)cellImageViewTapped:(UITapGestureRecognizer*)tap
{
    //判断点击 选中区域 区域之外的显示预览
    //    UIImageView * imageView = (UIImageView*)tap.view;
    //    CGPoint touch = [tap locationInView:imageView];
    
}

@end
